package cn.com.homeyoda.aimate.aihealth.ui.videoinspect;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import cn.com.homeyoda.aimate.aihealth.R;

public class ImproveInfoAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    private Context mContext;
    public Set<Integer> selectedItems = new HashSet<>();
    public Set<String> selectedString = new HashSet<>();

    public ImproveInfoAdapter(int layoutResId, @Nullable List<String> data, Context context) {
        super(layoutResId, data);
        mContext = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, String item) {

    }


    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.setText(R.id.problem_btn, getData().get(position));
        if (selectedItems.contains(position)) {
            holder.setBackgroundRes(R.id.problem_btn, R.mipmap.fankui_btn_foucs);
            holder.setTextColor(R.id.problem_btn, mContext.getResources().getColor(R.color.white));
        } else {
            holder.setBackgroundRes(R.id.problem_btn, R.mipmap.fankui_btn_normal);
            holder.setTextColor(R.id.problem_btn, mContext.getResources().getColor(R.color.black));
        }
        holder.addOnClickListener(R.id.problem_btn);
    }

    public void toggleSelection(int position) {
        if (selectedItems.contains(position)) {
            selectedItems.remove(position);
            selectedString.remove(getItem(position));
        } else {
            selectedItems.add(position);
            selectedString.add(getItem(position));
        }
        notifyItemChanged(position);
    }

    public Set<Integer> getSelectedItems() {
        return selectedItems;
    }

    public Set<String> getSelectedString() {
        return selectedString;
    }

    @Override
    public void setNewData(@Nullable List<String> data) {
        super.setNewData(data);
    }
}
